package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.vo.SysAssetDisposalVo;
import com.ruoyi.system.mapper.SysAssetMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysAssetDisposalMapper;
import com.ruoyi.system.domain.SysAssetDisposal;
import com.ruoyi.system.service.ISysAssetDisposalService;
import org.springframework.util.CollectionUtils;

/**
 * 资产处置Service业务层处理
 * 
 * @author sxy
 * @date 2025-04-02
 */
@Service
public class SysAssetDisposalServiceImpl implements ISysAssetDisposalService 
{
    @Autowired
    private SysAssetDisposalMapper sysAssetDisposalMapper;
    @Autowired
    private SysAssetMapper sysAssetMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询资产处置
     * 
     * @param disposalId 资产处置主键
     * @return 资产处置
     */
    @Override
    public SysAssetDisposalVo selectSysAssetDisposalByDisposalId(Long disposalId)
    {
        SysAssetDisposal sysAssetDisposal = sysAssetDisposalMapper.selectSysAssetDisposalByDisposalId(disposalId);
        SysAssetDisposalVo rsp = new SysAssetDisposalVo();
        BeanUtils.copyProperties(sysAssetDisposal, rsp);
        if(sysAssetDisposal.getAssetId() != null){
            rsp.setAssetName(sysAssetMapper.selectSysAssetByAssetId(sysAssetDisposal.getAssetId()).getAssetName());
        }
        if(sysAssetDisposal.getOperatorId() != null){
            rsp.setOperator(sysUserMapper.selectUserById(sysAssetDisposal.getOperatorId()).getUserName());
        }
        return rsp;
    }

    /**
     * 查询资产处置列表
     * 
     * @param sysAssetDisposal 资产处置
     * @return 资产处置
     */
    @Override
    public List<SysAssetDisposalVo> selectSysAssetDisposalList(SysAssetDisposal sysAssetDisposal)
    {
        List<SysAssetDisposal> sysAssetDisposals = sysAssetDisposalMapper.selectSysAssetDisposalList(sysAssetDisposal);
        List<SysAssetDisposalVo> rsp = new ArrayList<>();
        if(!CollectionUtils.isEmpty(sysAssetDisposals)){
            for (SysAssetDisposal disposal : sysAssetDisposals) {
                SysAssetDisposalVo disposalVo = new SysAssetDisposalVo();
                BeanUtils.copyProperties(disposal, disposalVo);
                if(disposal.getAssetId() != null){
                    disposalVo.setAssetName(sysAssetMapper.selectSysAssetByAssetId(disposal.getAssetId()).getAssetName());
                }
                if(disposal.getOperatorId() != null){
                    disposalVo.setOperator(sysUserMapper.selectUserById(disposal.getOperatorId()).getUserName());
                }
                rsp.add(disposalVo);
            }
        }
        return rsp;
    }

    /**
     * 新增资产处置
     * 
     * @param sysAssetDisposal 资产处置
     * @return 结果
     */
    @Override
    public int insertSysAssetDisposal(SysAssetDisposal sysAssetDisposal)
    {
        return sysAssetDisposalMapper.insertSysAssetDisposal(sysAssetDisposal);
    }

    /**
     * 修改资产处置
     * 
     * @param sysAssetDisposal 资产处置
     * @return 结果
     */
    @Override
    public int updateSysAssetDisposal(SysAssetDisposal sysAssetDisposal)
    {
        return sysAssetDisposalMapper.updateSysAssetDisposal(sysAssetDisposal);
    }

    /**
     * 批量删除资产处置
     * 
     * @param disposalIds 需要删除的资产处置主键
     * @return 结果
     */
    @Override
    public int deleteSysAssetDisposalByDisposalIds(Long[] disposalIds)
    {
        return sysAssetDisposalMapper.deleteSysAssetDisposalByDisposalIds(disposalIds);
    }

    /**
     * 删除资产处置信息
     * 
     * @param disposalId 资产处置主键
     * @return 结果
     */
    @Override
    public int deleteSysAssetDisposalByDisposalId(Long disposalId)
    {
        return sysAssetDisposalMapper.deleteSysAssetDisposalByDisposalId(disposalId);
    }
}
